{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 12.while语句"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 12.1基本语法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5050\n"
     ]
    }
   ],
   "source": [
    "i=1\n",
    "sum=0\n",
    "while(i<=100): \n",
    "    sum=sum+i\n",
    "    i+=1\n",
    "print(sum)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 12.2 注意事项"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2 1\n",
      "3 3\n",
      "4 6\n",
      "5 10\n",
      "7 21\n",
      "8 28\n"
     ]
    }
   ],
   "source": [
    "i=1\n",
    "sum=0\n",
    "while(i<=10):\n",
    "    sum=sum+i\n",
    "    i+=1\n",
    "    if i==6:\n",
    "        continue\n",
    "    if i==9:\n",
    "        break\n",
    "    print(i,sum)\n",
    "else:\n",
    "    print(\"here is esle\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2 1\n",
      "3 3\n",
      "4 6\n",
      "5 10\n",
      "6 15\n",
      "7 21\n",
      "8 28\n",
      "9 36\n",
      "10 45\n",
      "11 55\n",
      "here is esle\n"
     ]
    }
   ],
   "source": [
    "i=1\n",
    "sum=0\n",
    "while(i<=10):\n",
    "    sum=sum+i\n",
    "    i+=1\n",
    "    print(i,sum)\n",
    "else:\n",
    "    print(\"here is esle\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
